#include "master.h"
#include "log/Logging.h"

void Master::start()
{
    LOG_INFO << "Master::start()";
    allowRunning.store(true); // 设置允许运行为true

    taskThread = std::thread([this](){
        taskThreadFunc();
    });

    brokerThread = std::thread([this](){
        brokerThreadFunc();
    });

    mdnsServiceThread = std::thread([this](){
        mdnsServiceThreadFunc();
    });

    mqttClientThread = std::thread([this](){
        mqttClientThreadFunc();
    });

}


void Master::stop()
{   
    LOG_INFO << "Master::stop()";
    // 设置允许运行为false，停止所有线程
    allowRunning.store(false);

    if (taskThread.joinable()) {
        taskThread.join();
    }
    if (brokerThread.joinable()) {
        brokerThread.join();
    }
    if (mdnsServiceThread.joinable()) {
        mdnsServiceThread.join();
    }
    if (mqttClientThread.joinable()) {
        mqttClientThread.join();
    }
}


void Master::taskThreadFunc()
{   
    //
}

void Master::brokerThreadFunc()
{

}

void Master::mdnsServiceThreadFunc()
{

}

void Master::mqttClientThreadFunc()
{

}
